#encoding: utf-8

class OsseanStaGitMatchsController < ApplicationController
  def index
    
    #get users from stackoverflow_users
    per_page_option = 10
    @users_count = StackoverflowUser.count
    
    unless (params[:topnum] == nil)
      @users_count = params[:topnum].to_i
    end
    
    @users_pages = Paginator.new @users_count, per_page_option, params['page']
    
    @stackoverflow_users = StackoverflowUser.order("Reputation desc").offset(@users_pages.offset).limit(@users_pages.per_page)
    for i in (0..@stackoverflow_users.size-1)
      user = @stackoverflow_users[i]
      if(user.AboutMe != nil)
        @stackoverflow_users[i].AboutMe = PlainText.plain_text(@stackoverflow_users[i].AboutMe)
      end
    end
  end

  def show
    userId = params[:userId]
    @user = StackoverflowUser.find(userId)
    @userTag = UserTag.find(:first, :select => "id,AllTags", :conditions => ["UserId=?",@user.id])
    
    #get match result
    @matchResult = StaGitMatch.find(:all, :select => "*", :conditions => ["userId=?", @user.id])
    
    #get users from stackoverflow_users
    per_page_option = 10
    @projects_count = @matchResult.size
    
    unless (params[:topnum] == nil)
      @projects_count = params[:topnum].to_i
    end
    
    @projects_pages = Paginator.new @projects_count, per_page_option, params['page']
    
    @sta_git_matches = StaGitMatch.where(:userId => @user.id).order("match_score desc").offset(@projects_pages.offset).limit(@projects_pages.per_page)
    
    puts "@user.AboutMe.nil?"
  end
end
